package com.egame.manage.biz.server.op;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import cn.egame.common.exception.ExceptionCommonBase;
import cn.egame.common.model.PageData;
import cn.egame.ext.op.OperationActivityInfo;
import com.egame.manage.biz.server.ManageClientExt;

public class OperationActivityServiceImpl {
	
	private static OperationActivityServiceImpl instance = null;
	private static byte[] SyncRoot = new byte[1];
	private OperationActivityServiceDao dao = null;
	
	public static OperationActivityServiceImpl getInstance() throws ExceptionCommonBase {
		if (instance == null) {
			synchronized (SyncRoot) {
				if (instance == null) {
					instance = new OperationActivityServiceImpl();
				}
			}
		}
		return instance;
	}
	
	public OperationActivityServiceImpl() throws ExceptionCommonBase{
		super();
		dao = new OperationActivityServiceDao();
	}
	
	public int deleteAdvertisement(int appId, long loginUserId, int activityId)throws ExceptionCommonBase{
		return dao.deleteAdvertisement(activityId);
	}
	
	public List<Integer> listTerminalIds(int activityId) throws ExceptionCommonBase {
		return dao.listTerminalIdsByActivityId(activityId);
	}

	public int addAdapt(int activityId, int terminalId) throws ExceptionCommonBase {
		return dao.addAdapt(activityId,terminalId);
	}
	
	public int deleteAdapt(int activityId, int terminalId) throws ExceptionCommonBase {
		return dao.deleteAdapt(activityId, terminalId);
	}
	
	public PageData pageActivity(int appId, long loginUserId, OperationActivityInfo bean,List<Integer> terminalIds,List<Integer> position,int page,int rowsOfPage)throws RemoteException{
		List<Integer> ids = dao.listActivity(bean,terminalIds,position,page,rowsOfPage);
		List<OperationActivityInfo> list = new ArrayList<OperationActivityInfo>();
		OperationActivityInfo beanInfo = null;
		if(ids != null && ids.size()>0){
			for(Integer id:ids){
				beanInfo = ManageClientExt.getInstance().getOperationActivityInfoById(appId, loginUserId, id);
				if(beanInfo != null){
					list.add(beanInfo);
				}				
			}
		}		
		int total = dao.getActivityCount(bean,terminalIds,position);		
		PageData pd = new PageData(page, total, rowsOfPage);
		pd.setContent(list);		
		return pd;
	}
	
	public int upper(int appId, long loginUserId, int activityId) throws RemoteException {
		return dao.upper(appId, loginUserId, activityId);
	}
	
	public int lower(int appId, long loginUserId, int activityId) throws RemoteException {
		return dao.lower(appId, loginUserId, activityId);
	}
	
	public int getActivityId(long efsId)throws ExceptionCommonBase{
		return dao.getActivityIdByPicId(efsId);
	}
	
	public int getMaxSortNo(int type,int position)throws RemoteException{
		return dao.getMaxSortNo(type, position);
	}
	
	public int updateBigPic(int sortno)throws ExceptionCommonBase{
		return dao.updateBigPic(sortno);
	}
	
	public int deleteBigPic()throws ExceptionCommonBase{
		return dao.deleteBigPic();
	}
}
